package com.jh.concurrent.base.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title InterruptRecoverDemo.java
 * @package com.jh.concurrent.base.interrupt
 * @description 线程自身复位
 * @date 2019-05-09 16:56
 */
public class InterruptRecoverDemo {

    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println("befor：" + Thread.currentThread().isInterrupted());
                    // 线程复位
                    Thread.interrupted();
                    System.out.println("atfer：" + Thread.currentThread().isInterrupted());
                }
            }
        }, "thread");

        thread.start();
        TimeUnit.SECONDS.sleep(1);
        // 主线程中调用子线程的停止方法
        thread.interrupt();

    }

}
